package com.zc.manager.device.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.zc.manager.device.domain.IotDevice;
import com.zc.manager.device.request.DeviceGatewayMessageCountRequest;
import com.zc.manager.device.request.DeviceMessageCountRequest;
import com.zc.manager.device.service.ApiIotMetricsService;
import com.zc.manager.device.service.IIotDeviceService;
import com.zc.manager.device.service.IIotProductService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 设备指标
 *
 * @author xiepufeng
 */
@RestController
@RequestMapping("/api/iot/metrics")
public class ApiIotMetricsController extends BaseController {

    @Resource
    private IIotProductService iIotProductService;

    @Resource
    private IIotDeviceService iotDeviceService;

    @Resource
    private ApiIotMetricsService apiIotMetricsService;


    /**
     * 查询产品数量
     * @return 产品数量
     */
    @GetMapping("product/count")
    public AjaxResult productCount() {
        return AjaxResult.success(iIotProductService.productCount());
    }

    /**
     * 根据条件获取设备数量
     * @return 设备数量
     */
    @GetMapping("device/count")
    public AjaxResult deviceCount(IotDevice iotDevice) {
        return AjaxResult.success(iotDeviceService.getDeviceCount(iotDevice));
    }

    /**
     * 根据条件获取设备网关消息数量
     * @return 消息数量
     */
    @GetMapping("device-gateway/message/count")
    public AjaxResult deviceGatewayMessageCount(@Validated DeviceGatewayMessageCountRequest request) {
        return AjaxResult.success(apiIotMetricsService.deviceGatewayMessageCount(request));
    }

    /**
     * 根据条件获取设备消息数量
     * @return 消息数据
     */
    @GetMapping("device/message/count")
    public AjaxResult deviceMessageCount(@Validated DeviceMessageCountRequest request) {
        return AjaxResult.success(apiIotMetricsService.deviceMessageCount(request));
    }

}
